export const tree_mixin = {
  data() {
    return {
      tree: {
        nodes: [], //加载的数据
        entry: {}, //选中的node对象
        defaultKey: [],
        filter: '',
        props: {
          children: "children",
          label: "name",
          value: "id"
        },
      }
    }
  },
  methods: {
    /**节点过滤*/
    nodeFilter(value, data, node) {
      if (!value) return true;
      return node.label.indexOf(value) !== -1
    },
    /**节点单击击处理*/
    nodeClickHandle(data, node) {
      this.tree.entry = node
      this.$emit('choiceChange', data.id, data, node)
    },
    /**重置树*/
    treeReset() {
      this.tree.nodes = []
      this.tree.entry = {}
      this.tree.filter = ''
    },

    /**创建节点*/
    nodeCreate(data) {
      this.formMode(true, "添加", true, {
        ...data,
        validStatus: this.$constants.coreDict.validStatus.enum.enabled.value
      })
    },
    /**修改节点*/
    nodeModify(node, data) {
      this.formMode(true, "编辑", true, data)
    },
    /**删除节点*/
    nodeDelete(node, data) {
      if (data.children) {
        if (data.children.length > 0) {
          this.$message.warning("当前记录存在子集列表,请先删除所有子集!")
        }
      } else {
        this.entityDelete(node.data.id)
      }
    },
    /**三种刷新方式*/
    refreshCommand(command) {
      switch (command) {
        case 'keepStateRefresh':
          this.keepStateRefresh()
          break
        case 'specifySearch':
          this.specifySearch()
          break
        case 'initializeRefresh':
          this.initializeRefresh()
          break
        default:
          this.initializeRefresh()
          break
      }
    },
    /**重置分页刷新*/
    specifySearch() {
      this.treeLoadRefresh()
    },
    /**保持状态刷新*/
    keepStateRefresh() {
      this.treeLoadRefresh()
    },
    /**初始化刷新*/
    initializeRefresh() {
      this.treeReset()
      this.formReset()
      this.searchReset()
      this.treeLoadRefresh()
    },
  }
}